package com.sxyjhh.utils;

import com.sxyjhh.schedule.TaskSchedulerManager;
import org.apache.log4j.Logger;
import redis.clients.jedis.Jedis;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by Administrator on 2018/7/18.
 */
public class JedisUtil {

    private static final Logger logger = Logger.getLogger(TaskSchedulerManager.class);

  /*  private static BlockingQueue<Jedis> pools = new LinkedBlockingQueue<Jedis>();

    private static Jedis client = new Jedis("192.168.2.202", 6379, 60000);

    public static Jedis getclient() {
        return client;
    }

    public static Jedis getFactoryBean() throws Exception {
        if (pools.size() < 10) {
            Jedis add_client = new Jedis("192.168.2.202", 6379, 60000);
            pools.add(add_client);
        }
        return pools.take();
    }


    public static void setcache(String key, String value) {
        try {
            if (value != null && !"".equals(value) && key != null && !"".equals(key)) {
                JedisUtil.getclient().set(key, value);
            } else {
                logger.error(" 【JedisUtil save NULL】 key-value:" + key + "@value:" + value);
            }

        } catch (Exception e) {
            logger.error(" 【JedisUtil save exception】 key:" + key + "@value:" + value);
            try {
                getFactoryBean().set(key, value);
            } catch (Exception e1) {
                e1.printStackTrace();
                logger.error(" 【JedisUtil getFactoryBean exception】    key:" + key + "@value:" + value);
            }

        }

    }

    public static String get(String key) {
        String value = "";
        try {
            if (key != null && !"".equals(key)) {
                value = JedisUtil.getclient().get(key);
            } else {
                logger.error(" 【JedisUtil save NULL】 key-value:" + key + "@value:" + value);
            }

        } catch (Exception e) {
            logger.error(" 【JedisUtil get exception】 key:" + key);
            try {
                value = getFactoryBean().get(key);
            } catch (Exception e1) {
                e1.printStackTrace();
                logger.error(" 【JedisUtil getFactoryBean exception】    key:" + key);
            }

        }
        return value;
    }

    public static void del(String key) {
        try {
            if ( key != null && !"".equals(key)) {
                JedisUtil.getclient().del(key);
            } else {
                logger.error(" 【JedisUtil del NULL】 key-value:" + key);
            }

        } catch (Exception e) {
            logger.error(" 【JedisUtil save exception】 key:" + key );
            try {
                getFactoryBean().del(key);
            } catch (Exception e1) {
                e1.printStackTrace();
                logger.error(" 【JedisUtil getFactoryBean exception】    key:" + key );
            }

        }

    }*/
}